import io
p = r'static/js/admin.js'
s = io.open(p, 'r', encoding='utf-8').read()
start = s.find('template: `')
if start != -1:
    start_q = start + len('template: `')
    end = s.find('`', start_q)
    tpl = s[start_q:end]
    anchor = tpl.find('查看原始标准结构')
    insert_at = None
    if anchor != -1:
        sec_end = tpl.find('</section>', anchor)
        if sec_end != -1:
            insert_at = sec_end
    else:
        sec_start = tpl.find("<section v-if=\"activeTab === 'orders'\"")
        if sec_start != -1:
            sec_end = tpl.find('</section>', sec_start)
            if sec_end != -1:
                insert_at = sec_end
    if insert_at is not None:
        modal = "\n      <div v-if=\"jsonModal.visible\" class=\"modal-mask\" style=\"position:fixed;left:0;top:0;right:0;bottom:0;background:rgba(0,0,0,0.35);display:flex;align-items:center;justify-content:center;z-index:9999;\">\n        <div class=\"modal\" style=\"background:#fff;border-radius:8px;min-width:60vw;max-width:80vw;max-height:80vh;display:flex;flex-direction:column;box-shadow:0 8px 24px rgba(0,0,0,0.2);\">\n          <div style=\"display:flex;align-items:center;justify-content:space-between;padding:12px 16px;border-bottom:1px solid #eee;\">\n            <h3 style=\"margin:0;font-size:16px;\">{{ jsonModal.title }}</h3>\n            <button class=\"btn\" type=\"button\" @click=\"closeJsonModal\">关闭</button>\n          </div>\n          <div style=\"padding:12px;overflow:auto;\">\n            <pre style=\"margin:0;white-space:pre-wrap;word-break:break-all;\">{{ jsonModal.pretty }}</pre>\n          </div>\n        </div>\n      </div>\n"
        newtpl = tpl[:insert_at] + modal + tpl[insert_at:]
        s = s[:start_q] + newtpl + s[end:]
        io.open(p, 'w', encoding='utf-8', newline='\n').write(s)
        print('MODAL_INSERTED')
    else:
        print('ORDERS_SECTION_NOT_FOUND')
else:
    print('TEMPLATE_NOT_FOUND')
